/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package network;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
import javax.swing.text.html.HTMLDocument.RunElement;

/**
 *
 * @author Mark
 */
public class ServerConnection extends Thread
    {
    //Data Members
    private final int MAX_CLIENTS = 16;
    private int clientNum;
    private int port;
    private ServerSocket server;
    private ArrayList<LANChatClient> clients;
    public ServerConnection(boolean run, int port)
        {
        super();
        try 
            {
            server = new ServerSocket(port);
            clients = new ArrayList<LANChatClient>(MAX_CLIENTS);
            } 
        catch (IOException ex) 
            {
            System.out.println(ex);
            }
        if (run) 
            start();
        }
    @Override
    public void run()
        {
        while (MAX_CLIENTS > clientNum)
            {
            try
                {
                clients.add(new LANChatClient(server.accept(), "ChatClient" 
                    + clientNum++));
                }
            catch (IOException e)
                {
                System.out.print(e);
                }   
            }
        System.out.println("Max Clients Supported");
        }
    }
